package com.example.autoconfigstudy.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 一个自定义的条件，假设java.lang.String不在classPath中，那么条件为假，否则条件为真
 */
public class OnCustomCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        try {
            context.getClassLoader().loadClass("java.lang.String");
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }

    }
}
